package com.vmj.instructions.references;

import com.vmj.heap.ArrayObject;
import com.vmj.heap.VMObject;
import com.vmj.instructions.base.NoOperandsInstruction;
import com.vmj.rtda.Frame;
import com.vmj.rtda.OperandStack;

/**
 * Created by yangshoujun on 2017/9/9 上午11:03.
 */
public class ArrayLength extends NoOperandsInstruction {
    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        VMObject arrRef = stack.popRef();
        if(arrRef == null) {
            throw new RuntimeException("java.lang.NullPointerException");
        }
        int len = ArrayObject.getArrayLength(arrRef);
        stack.pushInt(len);

    }
}
